
Imports System
Imports System.Web.UI.WebControls
Imports System.Collections
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for adv_grp_search.
	''' </summary>
	Public Partial Class adv_grp_search
		Inherits BaseWebPage
		Protected txtCategoryText As System.Web.UI.WebControls.TextBox
		Protected hlAdvSearch As System.Web.UI.WebControls.HyperLink
		Protected imgAddFriends As System.Web.UI.WebControls.Image
		Protected lbJoin As System.Web.UI.WebControls.LinkButton
		Protected lblSearch As System.Web.UI.WebControls.Label
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			Me.pageTemplate.PageTitle = PageTitles.GROUP_ADV_SEARCH_PAGE

			Dim user As User = Me.LoggedUser
			If user = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If


			' init page from XML
			Me.initPageTitles(Constants.ADV_GROUP_SEARCH, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			' init tabs
			ucGroupTabs.ActiveTab = 5
			ucGroupTabs.PageName = Constants.ADV_GROUP_SEARCH

			If Constants.SHOW_GROUPS <> Constants.SHOW_ON Then
				Throw New Exception(Constants.ERROR_MESSAGE_NO_ACCESS)
			End If

			' Featured group
			Dim grp As Group = Groups.GetFeaturedGroup()
			If grp <> Nothing Then
				' get group image
				Dim grpPicture As GroupPicture = grp.DefaultPicture
				If grpPicture <> Nothing Then
					hlGroupPicture.ImageUrl = Pictures.GetPictureLargeThumbnailSrcFullURL(grpPicture, "../")
				Else
					hlGroupPicture.ImageUrl = "../images/default_thumbnail.gif"
				End If
				hlGroupPicture.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID
				hlGroupPicture.ToolTip = grp.Name
				hlGroupName.Text = grp.Name
				hlGroupName.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID

				hlCategory.Text = Constants.CATEGORIES.GetCategoryByID(grp.CatID).Name
				hlCategory.NavigateUrl = "../" + Constants.CATEGORY_GROUPS + "?" + Constants.CATEGORY_PARAM + "=" + grp.CatID

				hlViewGroup.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID
				hlJoinGroup.NavigateUrl = "../" + Constants.CONFIRM_JOIN_GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID

				If Not grp.PublicGroup Then
					lblGroupType.Text = GetPageConstText(htPageConstants, "CONST_PrivateGroup_TEXT")
				End If

				lblCreated.Text = grp.CreationDate.Day + "/" + grp.CreationDate.Month + "/" + grp.CreationDate.Year
				lblLocation.Text = grp.City + ", " + Constants.COUNTRIES.GetCountryByID(grp.CountryID).Name
				If grp.ShortAbout <> Nothing AndAlso grp.ShortAbout.Length > 0 Then
					lblAbout.Text = Server.HtmlEncode(getBeginning(grp.ShortAbout, Constants.MAX_GROUP_ABOUT_LENGTH))
				Else
					lblAbout.Text = "&nbsp;"
				End If
			Else
				hlGroupPicture.Visible = False
				hlGroupName.Visible = False
				hlCategory.Visible = False
				hlViewGroup.Visible = False
				lblSeparator.Visible = False
				hlJoinGroup.Visible = False
				lblGroupType.Visible = False
				lblCreated.Visible = False
				lblLocation.Visible = False
				lblAbout.Visible = False
				lblName.Text = GetPageConstText(htPageConstants, "CONST_NoFeaturedGroup_TEXT")
				lblCategory.Visible = False
				lblType.Visible = False
				lblCreatedDate.Visible = False
				lblLocationName.Visible = False
				lblAboutGroup.Visible = False
			End If

			If Not Me.IsPostBack Then
				' init categories dropdown
				Dim tmpLI As ListItem
				Dim categoriesCount As Integer = Constants.CATEGORIES.List.Count
				Dim tmpCategory As Categories.Category

				' select the misc category (so no search by category will be applied)
				ddlCategories.ClearSelection()
				tmpLI = New ListItem(Constants.MISC_CATEGORY_NAME, "-1")
				ddlCategories.Items.Add(tmpLI)
				ddlCategories.Items.FindByText(Constants.MISC_CATEGORY_NAME).Selected = True

				Dim i As Integer
				i = 0
				While i < categoriesCount
					tmpCategory = DirectCast(Constants.CATEGORIES.List(i), Categories.Category)
					tmpLI = New ListItem(tmpCategory.Name, tmpCategory.ID.ToString())
					ddlCategories.Items.Add(tmpLI)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While

				' init countries dropdown
				ddlCountry.Items.Add(New ListItem("-- Select Country --", "-1"))

				Dim countriesCount As Integer = Constants.COUNTRIES.List.Count
				Dim tempCountry As Countries.Country

				i = 0
				While i < countriesCount
					tempCountry = DirectCast(Constants.COUNTRIES.List(i), Countries.Country)
					ddlCountry.Items.Add(tempCountry.Name)
					ddlCountry.Items.FindByText(tempCountry.Name).Value = tempCountry.ID.ToString()
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While

				' select UK by default
				ddlCountry.ClearSelection()
				ddlCountry.Items.FindByValue(Countries.UKID.ToString()).Selected = True
			End If
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()

		End Sub
#End Region

		Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Dim filter As New GroupFilter()
			Dim usr As User = Me.LoggedUser
			Dim searchString As String = "<b>Search results for</b><br> "

			' set category
			Dim categoryID As Integer = Convert.ToInt32(Request.Params(ddlCategories.UniqueID))
			If categoryID <> -1 Then
				filter.categoryID = categoryID
				searchString += "<br>"
				searchString += "Category: " + Constants.CATEGORIES.GetCategoryByID(categoryID).Name
			End If

			' set search by name filter
			If Request.Params(chkName.UniqueID) = "on" Then
				filter.searchByName = True
			End If

			' set search by keyword filter
			If Request.Params(chkKeyword.UniqueID) = "on" Then
				filter.searchByKeyword = True
			End If

			' set search by keyword filter
			If Request.Params(txtKeyword.UniqueID) <> "" Then
				filter.keywords = Request.Params(txtKeyword.UniqueID)
			End If

			' set country
			Dim countyID As Integer = Convert.ToInt32(Request.Params(ddlCountry.UniqueID))
			If countyID <> -1 Then
				filter.countryID = countyID
				searchString += "<br>"
				searchString += "Country: " + Constants.COUNTRIES.GetCountryByID(countyID).Name
			End If

			' city / town
			Dim city As String = Request.Params(txtCity.UniqueID)
			If city <> Nothing AndAlso city <> "" Then
				filter.city = city
				searchString += "<br>"
				searchString += "City/Town: " + city
			End If

			' zip / postal code
			Dim zip As String = Request.Params(txtZip.UniqueID)
			If zip <> Nothing AndAlso zip <> "" Then
				filter.zip = zip
				searchString += "<br>"
				searchString += "Zip/Postal Code: " + zip
			End If

			searchString += "<br>"

			Session(Constants.ssnAdvGroupSearch_Criteria) = Server.UrlEncode(searchString)
			ssn_InitBrowseSession(filter)

			Response.Redirect(Constants.GROUP_SEARCH_RESULTS)
		End Sub

		Private Sub ssn_InitBrowseSession(ByVal f As GroupFilter)
			Session(Constants.ssnAdvGroupSearchFilter) = f
		End Sub

		====================
        ' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
        Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
            Get
                Return Migrated_Form1
            End Get
        End Property
        'set { Migrated_Form1 = value; }
    End Class
End Namespace






